import com.database.DataBaseBean;
import com.entity.UserEntity;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.inject.Inject;

/**
 * Created with IntelliJ IDEA.
 * User: x
 * Date: 2012.09.26.
 * Time: 17:45
 * To change this template use File | Settings | File Templates.
 */


@ManagedBean(name="managed")
@SessionScoped
public class DvdPdfSenderManagedBean{

    private String username;
    private String password;
    @Inject
    private DataBaseBean dataBaseBean;

    private boolean checked;

    public DvdPdfSenderManagedBean() {
    }

    public String login() {
        checked = dataBaseBean.isCheckedInit(username, password);
        try {
           dataBaseBean.add(new UserEntity(4,"fsfs","fdsfsd","fdsfs",2));
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        if (dataBaseBean.validate(username, password)) {
            return "loggedIn";
        }
        return "rejected";
    }


    public String submit() throws Exception{

        if(this.checked == true) {
            dataBaseBean.check(this.username);
        }else{
            dataBaseBean.unCheck(this.username);
        }
        return "afterSubmit";
    }


    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }
}
